#include "cSharedMemory.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const char* memoryName = "RobotSensorMem";
static int mem_fd = 0;
static void* shared_mem;

typedef struct _RobotSensor
{
    unsigned int id;
    float sensors[6];
} RobotSensor_T;

static RobotSensor_T sensor_msg;
RobotSensor_T* rd_sensor = NULL;

int main(void)
{
    sensor_msg.id = 0xAA03;
    sensor_msg.sensors[3] = 89.63f;
    shared_mem = mmCreateOnOpen((char*)memoryName, 64, &mem_fd);

    if(mem_fd < 0)
    {
        printf("Create Shared Memory Error.\n");
        return -1;
    }

    memcpy(shared_mem, (void *)&sensor_msg, sizeof(sensor_msg));
    printf("Start Shared Memory [%s]\n", memoryName);

    rd_sensor = (RobotSensor_T*)mmOpen((char*)memoryName, 64, &mem_fd);
    if(NULL != rd_sensor)
    {
        printf("Get Memory Info Id: 0x%04X\n", rd_sensor->id);
    }

    getchar();

    mmUnlink((char*)memoryName);
    return 0;
}